package com.ruoyi.system.service.impl;

import java.util.Collections;
import java.util.List;

import com.ruoyi.system.domain.CompanyCategroy;
import com.ruoyi.system.mapper.CompanyCategroyMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.CompanyGoodsMapper;
import com.ruoyi.system.domain.CompanyGoods;
import com.ruoyi.system.service.ICompanyGoodsService;

/**
 * 商家商品Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-08-20
 */
@Service
public class CompanyGoodsServiceImpl implements ICompanyGoodsService 
{
    @Autowired
    private CompanyGoodsMapper companyGoodsMapper;
    @Autowired
    private CompanyCategroyMapper companyCategroyMapper;

    /**
     * 查询商家商品
     * 
     * @param id 商家商品主键
     * @return 商家商品
     */
    @Override
    public CompanyGoods selectCompanyGoodsById(Long id)
    {
        return companyGoodsMapper.selectCompanyGoodsById(id);
    }

    /**
     * 查询商家商品列表
     * 
     * @param companyGoods 商家商品
     * @return 商家商品
     */
    @Override
    public List<CompanyGoods> selectCompanyGoodsList(CompanyGoods companyGoods)
    {
        return companyGoodsMapper.selectCompanyGoodsList(companyGoods);
    }

    /**
     * 查询商家商品列表_附加库存信息
     *
     * @param companyGoods 商家商品
     * @return 商家商品集合
     */
    @Override
    public List<CompanyGoods> selectCompanyGoodsList_stock(CompanyGoods companyGoods) {

        return companyGoodsMapper.selectCompanyGoodsList_stock(companyGoods);
    }

    /**
     * 新增商家商品
     * 
     * @param companyGoods 商家商品
     * @return 结果
     */
    @Override
    public int insertCompanyGoods(CompanyGoods companyGoods)
    {
        //处理分类名称
        if(companyGoods.getCategroyId()!=null){
            CompanyCategroy companyCategroy = companyCategroyMapper.selectCompanyCategroyById(companyGoods.getCategroyId());
            companyGoods.setCategroyName(companyCategroy.getName());
        }

        return companyGoodsMapper.insertCompanyGoods(companyGoods);
    }

    /**
     * 修改商家商品
     * 
     * @param companyGoods 商家商品
     * @return 结果
     */
    @Override
    public int updateCompanyGoods(CompanyGoods companyGoods)
    {
        //处理分类名称
        if(companyGoods.getCategroyId()!=null){
            CompanyCategroy companyCategroy = companyCategroyMapper.selectCompanyCategroyById(companyGoods.getCategroyId());
//            System.out.println("companyCategroy:"+companyCategroy.toString());
            companyGoods.setCategroyName(companyCategroy.getName());
        }
        return companyGoodsMapper.updateCompanyGoods(companyGoods);
    }

    /**
     * 批量删除商家商品
     * 
     * @param ids 需要删除的商家商品主键
     * @return 结果
     */
    @Override
    public int deleteCompanyGoodsByIds(Long[] ids)
    {
        return companyGoodsMapper.deleteCompanyGoodsByIds(ids);
    }

    /**
     * 删除商家商品信息
     * 
     * @param id 商家商品主键
     * @return 结果
     */
    @Override
    public int deleteCompanyGoodsById(Long id)
    {
        return companyGoodsMapper.deleteCompanyGoodsById(id);
    }
}
